package com.htudata.zabbix.api.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ItemZabbixApiService {

  @Autowired
  private BaseZabbixApiService baseZabbixApiService;

  public String createItems(JSONArray items) throws Exception {
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "item.create");
    request.put("params", items);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  public String updateItems(JSONArray items) throws Exception {
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "item.update");
    request.put("params", items);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  public String deleteItems(JSONArray itemIds) throws Exception {
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "item.delete");
    request.put("params", itemIds);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  public String getItems(JSONObject params) throws Exception {
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "item.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONResult(request);
  }
  
  @Deprecated
  private JSONArray getItemInfoByHostId(String[] output, String[] hostids) {
    JSONObject params = new JSONObject();
    params.put("output", output);
    params.put("hostids", hostids);
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "item.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONArrayResult(request);
  }
  
  @Deprecated
  private JSONArray getItemInfoByTemplateId(String[] output, String[] templateids) {
    JSONObject params = new JSONObject();
    params.put("output", output);
    params.put("templateids", templateids);
    JSONObject request = new JSONObject();
    request.put("jsonrpc", "2.0");
    request.put("method", "item.get");
    request.put("params", params);
    request.put("id", Integer.valueOf(0));
    return this.baseZabbixApiService.getJSONArrayResult(request);
  }
}
